using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class AnimationResourceFlow : MonoBehaviour
{
	public Image[] animationImages;

	private List<Tweener> animationTweens;

	public Ease animationEase = Ease.Linear;

	public float animationInitialDelay = 0.4f;

	public float animationMoveDuration = 0.2f;

	public float animationInterval = 0.07f;

	public float Show(Sprite sprite, RectTransform from, RectTransform to, int count = 10, float size = 60f, AudioClip clip = null, float volumeScale = 1f)
	{
		UserInterface.GetInstance().isAnimating = true;
		if (animationTweens == null)
		{
			animationTweens = new List<Tweener>();
		}
		float num = animationInitialDelay;
		if (count > animationImages.Length)
		{
			count = animationImages.Length;
		}
		for (int i = 0; i < count; i++)
		{
			Image target = animationImages[i];
			target.sprite = sprite;
			target.rectTransform.position = from.position;
			target.rectTransform.sizeDelta = new Vector2(size, 500f);
			Vector3 position = to.position;
			Tweener tweener = target.rectTransform.DOMove(position, animationMoveDuration);
			tweener.SetEase(animationEase);
			tweener.SetDelay(num);
			tweener.OnStart(delegate
			{
				target.gameObject.SetActive(true);
			});
			if (i < count - 1)
			{
				tweener.OnComplete(delegate
				{
					target.gameObject.SetActive(false);
					Audio.PlayShotSound(clip, volumeScale);
				});
			}
			else
			{
				tweener.OnComplete(delegate
				{
					target.gameObject.SetActive(false);
					Audio.PlayShotSound(clip, volumeScale);
					Stop();
				});
			}
			animationTweens.Add(tweener);
			num += animationInterval;
		}
		return num - animationInterval + animationMoveDuration;
	}

	public void Stop()
	{
		for (int i = 0; i < animationTweens.Count; i++)
		{
			if (animationTweens[i] != null)
			{
				animationTweens[i].Kill();
			}
		}
		animationTweens.Clear();
		for (int j = 0; j < animationImages.Length; j++)
		{
			animationImages[j].gameObject.SetActive(false);
		}
		UserInterface.GetInstance().isAnimating = false;
	}
}
